BitEncoderChannel.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. * Copyright (C) 2007-2014 Siemens AG
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Lesser General Public License as published
  6. * by the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*******************************************************************
  18. *
  19. * @author Daniel.Peintner.EXT@siemens.com
  20. * @version 0.9
  21. * @contact Joerg.Heuer@siemens.com
  22. *
  23. * <p>Code generated by EXIdizer</p>
  24. * <p>Schema: V2G_CI_MsgDef.xsd</p>
  25. *
  26. *
  27. ********************************************************************/
  28. #include "EncoderChannel.h"
  29. #include "EXIOptions.h"
  30. #include "BitOutputStream.h"
  31. #include "EXITypes.h"
  32. #ifndef BIT_ENCODER_CHANNEL_C
  33. #define BIT_ENCODER_CHANNEL_C
  34. #if EXI_OPTION_ALIGNMENT == BIT_PACKED
  35. int encode(bitstream_t* stream, uint8_t b) {
  36. return writeBits(stream, 8, b);
  37. }
  38. /**
  39. * Encode a single boolean value. A false value is encoded as bit 0 and true
  40. * value is encode as bit 1.
  41. */
  42. int encodeBoolean(bitstream_t* stream, int b) {
  43. uint8_t val = b ? 1 : 0;
  44. return writeBits(stream, 1, val);
  45. }
  46. /**
  47. * Encode n-bit unsigned integer. The n least significant bits of parameter
  48. * b starting with the most significant, i.e. from left to right.
  49. */
  50. int encodeNBitUnsignedInteger(bitstream_t* stream, uint16_t nbits, uint32_t val) {
  51. int errn = 0;
  52. if (nbits > 0) {
  53. errn = writeBits(stream, nbits, val);
  54. }
  55. return errn;
  56. }
  57. /**
  58. * Flush underlying bit output stream.
  59. */
  60. int encodeFinish(bitstream_t* stream) {
  61. return flush(stream);
  62. }
  63. #endif /* alignment */
  64. #endif