Skip to content

Commit

Permalink
Implement #528: Smile read/write features
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Nov 30, 2024
1 parent 57155b9 commit 5dcf3f1
Show file tree
Hide file tree
Showing 30 changed files with 314 additions and 302 deletions.
2 changes: 2 additions & 0 deletions release-notes/VERSION
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ implementations)
#524: JSTEP-8: rename `CBORGenerator.Feature` as `CBORWriteFeature`
#526: JSTEP-8: rename `IonParser.Feature` as `IonReadFeature`,
`IonGenerator.Feature` as `IonWriteFeature`
#528: JSTEP-8: rename `SmileParser.Feature` as `SmileReadFeature`,
`SmileGenerator.Feature` as `SmileWriteFeature`
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public class SmileFactory
* Bitfield (set of flags) of all parser features that are enabled
* by default.
*/
final static int DEFAULT_SMILE_PARSER_FEATURE_FLAGS = SmileParser.Feature.collectDefaults();
final static int DEFAULT_SMILE_PARSER_FEATURE_FLAGS = SmileReadFeature.collectDefaults();

/**
* Bitfield (set of flags) of all generator features that are enabled
* by default.
*/
final static int DEFAULT_SMILE_GENERATOR_FEATURE_FLAGS = SmileGenerator.Feature.collectDefaults();
final static int DEFAULT_SMILE_GENERATOR_FEATURE_FLAGS = SmileWriteFeature.collectDefaults();

/*
/**********************************************************************
Expand Down Expand Up @@ -163,14 +163,14 @@ public Version version() {
/**
* Checked whether specified parser feature is enabled.
*/
public final boolean isEnabled(SmileParser.Feature f) {
public final boolean isEnabled(SmileReadFeature f) {
return f.enabledIn(_formatReadFeatures);
}

/**
* Check whether specified generator feature is enabled.
*/
public final boolean isEnabled(SmileGenerator.Feature f) {
public final boolean isEnabled(SmileWriteFeature f) {
return f.enabledIn(_formatWriteFeatures);
}

Expand All @@ -191,13 +191,13 @@ public boolean canUseSchema(FormatSchema schema) {
}

@Override
public Class<SmileParser.Feature> getFormatReadFeatureType() {
return SmileParser.Feature.class;
public Class<SmileReadFeature> getFormatReadFeatureType() {
return SmileReadFeature.class;
}

@Override
public Class<SmileGenerator.Feature> getFormatWriteFeatureType() {
return SmileGenerator.Feature.class;
public Class<SmileWriteFeature> getFormatWriteFeatureType() {
return SmileWriteFeature.class;
}

/*
Expand Down Expand Up @@ -274,15 +274,15 @@ protected JsonGenerator _createGenerator(ObjectWriteContext writeCtxt,
SmileGenerator gen = new SmileGenerator(writeCtxt, ioCtxt,
writeCtxt.getStreamWriteFeatures(_streamWriteFeatures),
smileFeatures, out);
if (SmileGenerator.Feature.WRITE_HEADER.enabledIn(smileFeatures)) {
if (SmileWriteFeature.WRITE_HEADER.enabledIn(smileFeatures)) {
gen.writeHeader();
} else {
if (SmileGenerator.Feature.CHECK_SHARED_STRING_VALUES.enabledIn(smileFeatures)) {
if (SmileWriteFeature.CHECK_SHARED_STRING_VALUES.enabledIn(smileFeatures)) {
throw new StreamWriteException(gen,
"Inconsistent settings: WRITE_HEADER disabled, but CHECK_SHARED_STRING_VALUES enabled; can not construct generator"
+" due to possible data loss (either enable WRITE_HEADER, or disable CHECK_SHARED_STRING_VALUES to resolve)");
}
if (!SmileGenerator.Feature.ENCODE_BINARY_AS_7BIT.enabledIn(smileFeatures)) {
if (!SmileWriteFeature.ENCODE_BINARY_AS_7BIT.enabledIn(smileFeatures)) {
throw new StreamWriteException(gen,
"Inconsistent settings: WRITE_HEADER disabled, but ENCODE_BINARY_AS_7BIT disabled; can not construct generator"
+" due to possible data loss (either enable WRITE_HEADER, or ENCODE_BINARY_AS_7BIT to resolve)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,65 +43,65 @@ public SmileFactory build() {

// // // Parser features

public SmileFactoryBuilder enable(SmileParser.Feature f) {
public SmileFactoryBuilder enable(SmileReadFeature f) {
_formatReadFeatures |= f.getMask();
return _this();
}

public SmileFactoryBuilder enable(SmileParser.Feature first, SmileParser.Feature... other) {
public SmileFactoryBuilder enable(SmileReadFeature first, SmileReadFeature... other) {
_formatReadFeatures |= first.getMask();
for (SmileParser.Feature f : other) {
for (SmileReadFeature f : other) {
_formatReadFeatures |= f.getMask();
}
return _this();
}

public SmileFactoryBuilder disable(SmileParser.Feature f) {
public SmileFactoryBuilder disable(SmileReadFeature f) {
_formatReadFeatures &= ~f.getMask();
return _this();
}

public SmileFactoryBuilder disable(SmileParser.Feature first, SmileParser.Feature... other) {
public SmileFactoryBuilder disable(SmileReadFeature first, SmileReadFeature... other) {
_formatReadFeatures &= ~first.getMask();
for (SmileParser.Feature f : other) {
for (SmileReadFeature f : other) {
_formatReadFeatures &= ~f.getMask();
}
return _this();
}

public SmileFactoryBuilder configure(SmileParser.Feature f, boolean state) {
public SmileFactoryBuilder configure(SmileReadFeature f, boolean state) {
return state ? enable(f) : disable(f);
}

// // // Generator features

public SmileFactoryBuilder enable(SmileGenerator.Feature f) {
public SmileFactoryBuilder enable(SmileWriteFeature f) {
_formatWriteFeatures |= f.getMask();
return _this();
}

public SmileFactoryBuilder enable(SmileGenerator.Feature first, SmileGenerator.Feature... other) {
public SmileFactoryBuilder enable(SmileWriteFeature first, SmileWriteFeature... other) {
_formatWriteFeatures |= first.getMask();
for (SmileGenerator.Feature f : other) {
for (SmileWriteFeature f : other) {
_formatWriteFeatures |= f.getMask();
}
return _this();
}

public SmileFactoryBuilder disable(SmileGenerator.Feature f) {
public SmileFactoryBuilder disable(SmileWriteFeature f) {
_formatWriteFeatures &= ~f.getMask();
return _this();
}

public SmileFactoryBuilder disable(SmileGenerator.Feature first, SmileGenerator.Feature... other) {
public SmileFactoryBuilder disable(SmileWriteFeature first, SmileWriteFeature... other) {
_formatWriteFeatures &= ~first.getMask();
for (SmileGenerator.Feature f : other) {
for (SmileWriteFeature f : other) {
_formatWriteFeatures &= ~f.getMask();
}
return _this();
}

public SmileFactoryBuilder configure(SmileGenerator.Feature f, boolean state) {
public SmileFactoryBuilder configure(SmileWriteFeature f, boolean state) {
return state ? enable(f) : disable(f);
}
}
Loading

0 comments on commit 5dcf3f1

Please sign in to comment.