mirror of
https://github.com/esiur/esiur-js.git
synced 2025-06-27 15:23:11 +00:00
2.0.0
This commit is contained in:
46
src/Resource/Template/ConstantTemplate.js
Normal file
46
src/Resource/Template/ConstantTemplate.js
Normal file
@ -0,0 +1,46 @@
|
||||
import {DC, BL} from '../../Data/DC.js';
|
||||
import MemberTemplate from './MemberTemplate.js';
|
||||
import Codec from '../../Data/Codec.js';
|
||||
|
||||
export default class ConstantTemplate extends MemberTemplate {
|
||||
//final dynamic value;
|
||||
//final String? expansion;
|
||||
//final RepresentationType valueType;
|
||||
|
||||
constructor(template, index, name,
|
||||
inherited, valueType, value, expansion){
|
||||
super(template, index, name, inherited) ;
|
||||
this.valueType = valueType;
|
||||
this.value = value;
|
||||
this.expansion = expansion;
|
||||
}
|
||||
|
||||
compose() {
|
||||
var name = super.compose();
|
||||
var hdr = this.inherited ? 0x80 : 0;
|
||||
|
||||
if (this.expansion != null) {
|
||||
var exp = DC.stringToBytes(this.expansion);
|
||||
hdr |= 0x70;
|
||||
return (BL()
|
||||
.addUint8(hdr)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(this.valueType.compose())
|
||||
.addDC(Codec.compose(this.value, null))
|
||||
.addInt32(exp.length)
|
||||
.addDC(exp))
|
||||
.toDC();
|
||||
} else {
|
||||
hdr |= 0x60;
|
||||
|
||||
return (BL()
|
||||
.addUint8(hdr)
|
||||
.addUint8(name.length)
|
||||
.addDC(name)
|
||||
.addDC(this.valueType.compose())
|
||||
.addDC(Codec.compose(this.value, null)))
|
||||
.toDC();
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user