com.iab.gpp.encoder.segment.TcfCaV1DisclosedVendorsSegment Maven / Gradle / Ivy
The newest version!
package com.iab.gpp.encoder.segment;
import java.util.ArrayList;
import java.util.List;
import com.iab.gpp.encoder.base64.AbstractBase64UrlEncoder;
import com.iab.gpp.encoder.base64.CompressedBase64UrlEncoder;
import com.iab.gpp.encoder.bitstring.BitStringEncoder;
import com.iab.gpp.encoder.datatype.EncodableFixedInteger;
import com.iab.gpp.encoder.datatype.EncodableOptimizedFixedRange;
import com.iab.gpp.encoder.error.DecodingException;
import com.iab.gpp.encoder.field.EncodableBitStringFields;
import com.iab.gpp.encoder.field.TcfCaV1Field;
public class TcfCaV1DisclosedVendorsSegment extends AbstractLazilyEncodableSegment {
private AbstractBase64UrlEncoder base64UrlEncoder = CompressedBase64UrlEncoder.getInstance();
private BitStringEncoder bitStringEncoder = BitStringEncoder.getInstance();
public TcfCaV1DisclosedVendorsSegment() {
super();
}
public TcfCaV1DisclosedVendorsSegment(String encodedString) {
super();
this.decode(encodedString);
}
@Override
public List getFieldNames() {
return TcfCaV1Field.TCFCAV1_DISCLOSED_VENDORS_SEGMENT_FIELD_NAMES;
}
@Override
protected EncodableBitStringFields initializeFields() {
EncodableBitStringFields fields = new EncodableBitStringFields();
fields.put(TcfCaV1Field.DISCLOSED_VENDORS_SEGMENT_TYPE, new EncodableFixedInteger(3, 1));
fields.put(TcfCaV1Field.DISCLOSED_VENDORS, new EncodableOptimizedFixedRange(new ArrayList<>()));
return fields;
}
@Override
protected String encodeSegment(EncodableBitStringFields fields) {
String bitString = bitStringEncoder.encode(fields, getFieldNames());
String encodedString = base64UrlEncoder.encode(bitString);
return encodedString;
}
@Override
protected void decodeSegment(String encodedString, EncodableBitStringFields fields) {
if (encodedString == null || encodedString.isEmpty()) {
this.fields.reset(fields);
}
try {
String bitString = base64UrlEncoder.decode(encodedString);
bitStringEncoder.decode(bitString, getFieldNames(), fields);
} catch (Exception e) {
throw new DecodingException("Unable to decode TcfCaV1DisclosedVendorsSegment '" + encodedString + "'", e);
}
}
}